//app.js
import {getNowTime} from "./utils/utils"
App({
 
  buf2hex: function (buffer) {
    return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('')
  },
  buf2string: function (buffer) {
    var arr = Array.prototype.map.call(new Uint8Array(buffer), x => x)
    var str = ''
    for (var i = 0; i < arr.length; i++) {
      str += String.fromCharCode(arr[i])
    }
    return str
  },
  onLaunch: function () {
    this.globalData.SystemInfo = wx.getSystemInfoSync()
    //console.log(this.globalData.SystemInfo)
    wx.cloud.init({
      env:"cloud1-6ge3xp2t2b4843d4"
    })
    // 调用云函数
    wx.cloud.callFunction({
      name:"get_openId",
      success:res=>{
        // 获得openId
        this.globalData.user_openId=res.result.openid
        // console.log("获得openID",this.globalData.user_openId);
        // 查找是否已经登录过了
        wx.cloud.database().collection('userInfo').where({  
          _openid:res.result.openid
        }).get({
          success:result=>{
            // 设置自动登录
            wx.setStorageSync('userInfo',result.data[0])
            this.globalData.userInfo=result.data[0]
          }
        })
      }
    })
  },
  globalData: {
    SystemInfo: {},
    user_openId:"",
    userInfo:null,
    isActive:"asd",
    bindUserInfo:null
  }
})